from alg1 import Solution

def test_hamming_weight():
    solution = Solution()
    correct = 0
    total = 0

    # 读取测试用例
    with open('input.txt', 'r') as f:
        n_cases = int(f.readline().strip())
        for _ in range(n_cases):
            num = int(f.readline().strip())
            total += 1

            # 计算预期结果（使用bin函数计算1的个数作为验证）
            expected = bin(num).count('1')
            result = solution.hammingWeight(num)

            # 验证结果
            if result == expected:
                correct += 1
            else:
                print(f"Test case failed for number {num}")
                print(f"Expected: {expected}, Got: {result}")

    # 输出测试结果
    print(f"\nTest Results:")
    print(f"Total test cases: {total}")
    print(f"Correct: {correct}")
    print(f"Success rate: {(correct/total)*100:.2f}%")

if __name__ == '__main__':
    test_hamming_weight()
